package com.example.administrator.printoutindemo;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


import com.example.administrator.printoutindemo.bean.ErweimaCun;
import com.example.administrator.printoutindemo.http.HttpManager;
import com.example.administrator.printoutindemo.zxing.activity.CaptureActivity;
import com.jess.arms.utils.ToastUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import rx.Subscriber;

/**
 * Created by Administrator on 2019/3/9.
 */

public class JianyanActivity extends AppCompatActivity {
    private ImageView iv_qysaomiao;
    private TextView tv_quyangdizhi;
    private EditText et_yijian;
    private TextView tv_tijiao;
    private String scanResult;
    ErweimaCun erweimaCun;
    List<String> list;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jianyan);
        list=new ArrayList<>();
        erweimaCun=new ErweimaCun();
        iv_qysaomiao= (ImageView) findViewById(R.id.iv_qysaomiao);
        tv_quyangdizhi= (TextView) findViewById(R.id.tv_quyangdizhi);
        et_yijian= (EditText) findViewById(R.id.et_yijian);
        tv_tijiao= (TextView) findViewById(R.id.tv_tijiao);
        tv_tijiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                if (list.size()==2){
//                    String a=list.get(0);
//                    String a1=a.substring(0,a.indexOf("_"));
//                    String b=list.get(1);
//                    String b1=b.substring(0,b.indexOf("_"));
//                    if (a1.equals(b1)){
//                        tv_quyangdizhi.setText(a1);
                HashMap<String,String> map=new HashMap<>();
                map.put("monthid",tv_quyangdizhi.getText().toString());
                map.put("opinion",et_yijian.getText().toString());
                HttpManager.getInstance().post("SaveCheckOpinion", map, new Observer<String>() {

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @SuppressLint("LongLogTag")
                    @Override
                    public void onNext(String s) {
                        char[] str = s.toCharArray();
                        Log.e("dayinjiancejieguo==1111===",s);
                        String ss = s.substring(75, str.length - 9);
                        Log.e("dayinjiancejieguo=====",ss);
                        if (ss.equals("success")){
                            Log.e("dayinjiancejieguo==333333333333333333===",ss);
                            Toast.makeText(JianyanActivity.this,"提交成功",Toast.LENGTH_LONG).show();
                            tv_quyangdizhi.setText("");
                            et_yijian.setText("");
                        }else {
                            Toast.makeText(JianyanActivity.this,"提交失败",Toast.LENGTH_LONG).show();
                        }
                    }
                });
//                    }
//                }


            }
        });

        iv_qysaomiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent openCameraIntent = new Intent(JianyanActivity.this,
                        CaptureActivity.class);
                startActivityForResult(openCameraIntent, 0);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK) {
            Bundle bundle = data.getExtras();
            scanResult = bundle.getString("result");
            if (scanResult != null | TextUtils.isEmpty(scanResult)) {
                tv_quyangdizhi.setText(scanResult);
            }
        }
    }
}
